* Replication code for:

*** Anne Rasmussen & Stefanie Reher, 
*** "(Inequality in) Interest Group Involvement and the Legitimacy of Policy-Making", 
*** British Journal of Political Science, 2022

* 12 April 2022

************************************************************************

* Save the dataset "RR_BJPS_2022.dta" and replace "PATH" below with the path to its folder:
global wd "PATH"

use $wd\RR_BJPOLS_2022.dta, clear

* Drop cases who failed at least one attention check or more than half of manipulation checks
drop if failedattention==1 | failedmanipulation==1

************************************************************************

*** Table 1: OLS regressions of legitimacy on representation and moderating variables

* Model 1
regress leg_proc ib2.repres ib2.attain i.public outfav group issue i.country, cluster(id)
est store M1

* Model 2
regress leg_proc ib2.repres##c.res_econ_difference ib2.attain##c.res_econ_difference i.public outfav group issue i.country, cluster(id)
est store M2
	* code for Figure 4
	cap gen m1=1 if leg_proc!=. & repres!=. & attain!=. & public!=. & outfav!=. & group!=. & issue!=. & country!=. 
	margins, at(res_econ_difference=(-4(1)4)) by(repres)
	marginsplot, xtitle("Relative perceived economic resources", size(medium)) ytitle(" ") ///
		title(" ") recast(line) recastci(rarea) xsize(3.2) ysize(4.5) graphregion(color(white)) ///
		addplot(hist res_econ_difference if m1==1, width(1) yaxis(2) yscale(alt) fcolor(%10) ) ///
		name(g1, replace)

* Model 3
regress leg_proc ib2.repres##c.res_repres_difference ib2.attain##c.res_repres_difference i.public outfav group issue i.country, cluster(id)
est store M3
	* Figure 4
	margins, at(res_repres_difference=(-4(1)4)) by(repres)
	marginsplot, xtitle("Relative perceived representativeness", size(medium)) ytitle(" ") ///
		title(" ") recast(line) recastci(rarea) xsize(3.2) ysize(4.5) graphregion(color(white)) ///
		addplot(hist res_repres_difference if m1==1, width(1) yaxis(2) yscale(alt) fcolor(%10) ) ///
		name(g2, replace)
	graph combine g1 g2, col(2) l1title("Density", size(medium)) r1title("Predicted legitimacy", size(medium)) name(g3, replace)
	graph save g3 $wd\Fig4.gph, replace
	graph export $wd\Fig4.png, replace

* Model 4
regress leg_proc ib2.repres##ib2.attain i.public outfav group issue i.country, cluster(id) 
* other reference categories pof attain for coefficients in Fig 5
regress leg_proc ib2.repres##ib3.attain i.public outfav group issue i.country, cluster(id) 
regress leg_proc ib2.repres##ib4.attain i.public outfav group issue i.country, cluster(id) 

est store M4

* Table 1
esttab M1 M2 M3 M4 using $wd\Table1.rtf, replace ///
		b(%10.3f) se bic obslast star(* 0.05 ** 0.01 *** 0.001) ///
		mtitles ("(1)" "(2)" "(3)" "(4)") label nogaps compress nonumbers nonotes 

*** See R script for code for Figures 2 and 5

************************************************************************
************************************************************************

*** SUPPLEMENTARY INFORMATION

************************************************************************
************************************************************************

*** SI 2: Verifying the legitimacy scales

* Cronbach's alpha for procedural legitimacy items:
alpha leg_fair leg_actors leg_democratic
* Cronbach's alpha for substantive legitimacy items:
alpha leg_right leg_citizens leg_affected

* Factor analysis (Table S2):
factor leg_fair leg_right leg_actors leg_citizens leg_democratic leg_affected
rotate, oblique oblimin

************************************************************************
************************************************************************

*** SI 3: Diagnostics 

*** 3.1. Issue order

* Group 1
regress leg_proc ib2.repres ib2.attain i.public outfav group issue i.country, cluster(id), if group==1
est store M1
* Group 2
regress leg_proc ib2.repres ib2.attain i.public outfav group issue i.country, cluster(id), if group==2
est store M2
* Table S3
esttab M1 M2 using $wd\TableS3.rtf, replace  ///
		b(%10.3f) se bic obslast star(* 0.05 ** 0.01 *** 0.001) ///
		mtitles ("Group 1 (hybrid, sugar)" "Group 2 (sugar, hybrid)") label nogaps compress nonumbers nonotes 
		
*** 3.2. Randomization

regress age i.repres i.attain i.public i.country, cluster(id)
est store M1
regress female i.repres i.attain i.public i.country, cluster(id)
est store M2
* Table S4
esttab M1 M2 using $wd\TableS4.rtf, replace  ///
		b(%10.3f) se bic obslast star(* 0.05 ** 0.01 *** 0.001) ///
		mtitles ("Age" "Female") label nogaps compress nonumbers nonotes 

************************************************************************
************************************************************************

*** SI 4: Analyses on sample including respondents who failed attention and manipulation checks

* load dataset again and don't drop cases based on failed attention and manipulation checks
use $wd\RR_BJPOLS_2022.dta, clear

* Model 1
regress leg_proc ib2.repres ib2.attain i.public outfav group issue i.country, cluster(id)
est store M1
* Model 2
regress leg_proc ib2.repres##c.res_econ_difference ib2.attain##c.res_econ_difference i.public outfav group issue i.country, cluster(id)
est store M2
* Model 3
regress leg_proc ib2.repres##c.res_repres_difference ib2.attain##c.res_repres_difference i.public outfav group issue i.country, cluster(id)
est store M3
* Model 4
regress leg_proc ib2.repres##ib2.attain i.public outfav group issue i.country, cluster(id) 
est store M4
* Table S5
esttab M1 M2 M3 M4 using $wd\TableS5.rtf, replace ///
		b(%10.3f) se bic obslast star(* 0.05 ** 0.01 *** 0.001) ///
		mtitles ("(1)" "(2)" "(3)" "(4)") label	nogaps compress nonumbers nonotes
		
************************************************************************
************************************************************************

*** SI 5: Analyses split by country

* Drop cases who failed at least one attention check or more than half of manipulation checks (keep for robustness checks in SI 4, Table S4)
drop if failedattention==1 | failedmanipulation==1
*UK and US
forval i=1/2 {
* Model 1
regress leg_proc ib2.repres ib2.attain i.public outfav group issue, cluster(id), if country==`i'
est store M1`i'

* Model 2
regress leg_proc ib2.repres##c.res_econ_difference ib2.attain##c.res_econ_difference i.public outfav group issue, cluster(id), if country==`i'
est store M2`i'

* Model 3
regress leg_proc ib2.repres##c.res_repres_difference ib2.attain##c.res_repres_difference i.public outfav group issue, cluster(id), if country==`i'
est store M3`i'

* Model 4
regress leg_proc ib2.repres##ib2.attain i.public outfav group issue, cluster(id), if country==`i'
est store M4`i'
}
* Germany
* Model 1
regress leg_proc ib2.repres ib2.attain i.public outfav group issue, cluster(id), if country==3
est store M13
* Model 4
regress leg_proc ib2.repres##ib2.attain i.public outfav group issue, cluster(id), if country==3
est store M43
* Tables S6 - S8
esttab M11 M21 M31 M41 using $wd\TableS6-UK.rtf, replace ///
		b(%10.3f) se bic obslast star(* 0.05 ** 0.01 *** 0.001) ///
		mtitles ("(1)" "(2)" "(3)" "(4)") label	nogaps compress nonumbers nonotes
esttab M12 M22 M32 M42 using $wd\TableS7-US.rtf, replace ///
		b(%10.3f) se bic obslast star(* 0.05 ** 0.01 *** 0.001) ///
		mtitles ("(1)" "(2)" "(3)" "(4)") label	nogaps compress nonumbers nonotes
esttab M13 M43 using $wd\TableS8-DE.rtf, replace ///
		b(%10.3f) se bic obslast star(* 0.05 ** 0.01 *** 0.001) ///
		mtitles ("(1)" "(4)") label nogaps compress nonumbers nonotes

************************************************************************
************************************************************************

*** SI 6: Analysis for each component of legitimacy scale
foreach i in fair actors democratic {
* Model 1
regress leg_`i' ib2.repres ib2.attain i.public outfav group issue i.country, cluster(id)
est store M`i'
}
* Table S9
esttab Mfair Mactors Mdemocratic using $wd\TableS9.rtf, replace ///
		b(%10.3f) se bic obslast star(* 0.05 ** 0.01 *** 0.001) ///
		mtitles ("Process was fair" "Views of all relevant actors taken into account" ///
				"Process was democratic") label	nogaps compress nonumbers nonotes

************************************************************************
************************************************************************

*** SI 7: Analysis of economic resource and representativeness effects, controlling for ideology
		
* Model 2
regress leg_proc ib2.repres##c.res_econ_difference ib2.attain##c.res_econ_difference ///
	ib2.repres##c.ideology ib2.attain##c.ideology i.public outfav group issue i.country, cluster(id)
est store M1
* Model 3
regress leg_proc ib2.repres##c.res_repres_difference ib2.attain##c.res_repres_difference ///
	ib2.repres##c.ideology ib2.attain##c.ideology i.public outfav group issue i.country, cluster(id)
est store M3
* Table S10
esttab M1 M3 using $wd\TableS10.rtf, replace ///
		b(%10.3f) se bic obslast star(* 0.05 ** 0.01 *** 0.001) ///
		mtitles ("(2)" "(3)") label	nogaps compress nonumbers nonotes




